package com.dews.web.controller.information;

import com.dews.common.annotation.Log;
import com.dews.common.core.controller.BaseController;
import com.dews.common.core.domain.BaseResponse;
import com.dews.common.core.page.TableDataInfo;
import com.dews.common.enums.BusinessType;
import com.dews.common.utils.poi.ExcelUtil;
import com.dews.common.utils.valid.AddGroup;
import com.dews.common.utils.valid.UpdateGroup;
import com.dews.information.domain.dto.StudentInfoDTO;
import com.dews.information.domain.dto.StudentInfoQueryDTO;
import com.dews.information.domain.vo.StudentInfoVo;
import com.dews.information.service.IStudentInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

/**
 * 学生信息详情Controller
 * 
 * @author qingfeng
 * @date 2025-01-14
 */
@Api(value = "学生信息详情", tags = {"学生信息详情" })
@RestController
@Validated
@RequestMapping("/student/info")
public class StudentInfoController extends BaseController {

    private IStudentInfoService studentInfoService;

    @Autowired
    public StudentInfoController(IStudentInfoService studentInfoService) {
        this.studentInfoService = studentInfoService;
    }

    @ApiOperation(value = "获取学生信息详情列表")
    @PreAuthorize("@ss.hasPermi('student:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(@Validated StudentInfoQueryDTO studentInfoQueryDTO) {
        startPage();
        List<StudentInfoVo> list = studentInfoService.selectStudentInfoList(studentInfoQueryDTO);
        return getDataTable(list);
    }

    @ApiOperation(value = "新增学生信息详情")
    @PreAuthorize("@ss.hasPermi('student:info:add')")
    @Log(title = "学生信息详情", businessType = BusinessType.INSERT)
    @PostMapping
    public BaseResponse add(@RequestBody @Validated(AddGroup.class) StudentInfoDTO studentInfoDTO) {
        return toAjax(studentInfoService.insertStudentInfo(studentInfoDTO));
    }

    @ApiOperation(value = "修改学生信息详情")
    @PreAuthorize("@ss.hasPermi('student:info:edit')")
    @Log(title = "学生信息详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public BaseResponse edit(@RequestBody @Validated(UpdateGroup.class) StudentInfoDTO studentInfoDTO) {
        return toAjax(studentInfoService.updateStudentInfo(studentInfoDTO));
    }

    @ApiOperation(value = "获取学生信息详情详细信息")
    @PreAuthorize("@ss.hasPermi('student:info:query')")
    @GetMapping(value = "/{id}")
    public BaseResponse getInfo(@PathVariable("id") Integer id) {
        return success(studentInfoService.selectStudentInfoById(id));
    }

    @ApiOperation(value = "删除学生信息详情")
    @PreAuthorize("@ss.hasPermi('student:info:remove')")
    @Log(title = "学生信息详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public BaseResponse remove(@PathVariable List<Integer> ids) {
        return toAjax(studentInfoService.deleteStudentInfoByIds(ids));
    }

    @ApiOperation(value = "导出学生信息详情列表")
    @PreAuthorize("@ss.hasPermi('student:info:export')")
    @Log(title = "学生信息详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentInfoVo studentInfoVo) {
        List<StudentInfoVo> list = Collections.emptyList();
        ExcelUtil<StudentInfoVo> util = new ExcelUtil<StudentInfoVo>(StudentInfoVo.class);
        util.exportExcel(response, list, "学生信息详情数据");
    }

    @ApiOperation(value = "查询学生个人的学籍信息")
    @GetMapping("/grade")
    public BaseResponse getStudentGradeInfo() {
        return success(studentInfoService.getStudentGradeInfo());
    }

}
